﻿<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [DirectMethod]
    public void OnTriggerClick()
    {
        X.AddScript("ModelTypeStore.reload()");
    }
    
   
    
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
    <title>产品列表</title>
    <script type="text/javascript" src="/Scripts/Commen.js"></script>
    <script type="text/javascript" src="/Scripts/BD_Product/BD_Product_Index.js"></script>
</head>
<body>
    <script type="text/javascript" src="/Scripts/ExtTimeOut.js"></script>
    <script type="text/javascript" src="/Scripts/ExtRequiredFieldPluins.js"></script>
    <script type="text/javascript">
        var changeProdNumSortDirect = function () {
            ProdctSortColumn.Value = "ProductNumber";
            if (ProdNumSortDirect.Value == "ASC" || ProdNumSortDirect.Value == "") {
                ProdNumSortDirect.Value = "DESC";
            }
            else {
                ProdNumSortDirect.Value = "ASC";
            }
        };
    </script>
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Hidden ID="ProdNumSortDirect" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <ext:Hidden ID="ProdctSortColumn" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <ext:Store ID="productInvStore" runat="server" AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/Product/getProdInvStatusTypeList" />
        </Proxy>
        <Reader>
            <ext:JsonReader Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FId" />
                    <ext:RecordField Name="FName" />
                    <ext:RecordField Name="FNumber" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <!--列表数据源-->
    <ext:Store ID="ProductListStore" IDMode="Explicit" runat="server" RemoteSort="true"
        SkipIdForNewRecords="false" UseIdConfirmation="false" SerializationMode="Complex">
        <Proxy>
            <ext:HttpProxy Url="/Product/ProductListPaging" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="ProductId" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="ProductNumber" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="ProductModelId" />
                    <ext:RecordField Name="ProductModelName" />
                    <ext:RecordField Name="ProductUnitId" />
                    <ext:RecordField Name="ProductUnitName" />
                    <ext:RecordField Name="ProductQty" />
                    <ext:RecordField Name="ProductRemark" />
                    <ext:RecordField Name="LastModeifyTime" Type="Date" />
                    <ext:RecordField Name="ProductPrice1" />
                    <ext:RecordField Name="ProductPrice2" />
                    <ext:RecordField Name="ProductPrice3" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="limit" Value="15" Mode="Raw" />
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="fNumber" Value="#{InputQ_ProductNumber}.getValue()" Mode="Raw" />
            <ext:Parameter Name="fName" Value="#{InputQ_ProductName}.getValue()" Mode="Raw" />
            <ext:Parameter Name="fModelId" Value="#{InputQ_ModelTypeSelect}.getValue()" Mode="Raw" />
            <ext:Parameter Name="fReMark" Value="#{InputQ_ProductRemark}.getValue()" Mode="Raw" />
            <ext:Parameter Name="fProdInvStatusName" Value="#{InputQ_ProductInvStatus}.getValue()"
                Mode="Raw" />
            <ext:Parameter Name="dir" Value="#{ProdNumSortDirect}.getValue()" Mode="Raw" />
            <ext:Parameter Name="sort" Value="#{ProdctSortColumn}.getValue()" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <!--编辑数据源-->
    <ext:Hidden ID="FIdH" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <ext:Store ID="PordEidtStore" runat="server" AutoLoad="false">
        <Proxy>
            <ext:HttpProxy Url="/Product/getProductListByID" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="ProductId" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="ProductNumber" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="ProductModelId" />
                    <ext:RecordField Name="ProductModelName" />
                    <ext:RecordField Name="ProductUnitId" />
                    <ext:RecordField Name="ProductUnitName" />
                    <ext:RecordField Name="ProductQty" />
                    <ext:RecordField Name="ProductRemark" />
                    <ext:RecordField Name="LastModeifyTime" Type="Date" />
                    <ext:RecordField Name="ProductPrice1" />
                    <ext:RecordField Name="ProductPrice2" />
                    <ext:RecordField Name="ProductPrice3" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="fId" Value="#{FIdH}.getValue()" Mode="Raw" />
            <ext:Parameter Name="dir" Value="ASC" />
            <ext:Parameter Name="sort" Value="ProductId" />
        </BaseParams>
        <Listeners>
            <BeforeLoad Handler="#{EditFormPanel}.el.mask('正在加载信息...', 'x-mask-loading');" />
            <LoadException Handler="#{EditFormPanel}.el.unmask();" />
            <Load Fn="BD_Product.Mgr.formStoreLoaded" />
        </Listeners>
    </ext:Store>
    <ext:Store ID="ModelTypeStore" runat="server" AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/Product/GetModelTypes/" />
        </Proxy>
        <Reader>
            <ext:JsonReader Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FId" />
                    <ext:RecordField Name="FName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
     <ext:Store ID="UnitStore"  runat="server"  AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/Product/GetUnits/" />
        </Proxy>
        <Reader>
            <ext:JsonReader Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FId" />
                    <ext:RecordField Name="FName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="ProductViewport" runat="server" Layout="BorderLayout">
        <Items>
            <ext:FormPanel ID="EditFormPanel" runat="server" Title="产品编辑" Region="North" Split="true"
                Height="150" Collapsible="true" Layout="HBoxLayout" Padding="5" AnchorHorizontal="100%"
                LabelWidth="60" Url="/Product/SaveOrUpadteProduct">
                <TopBar>
                    <ext:Toolbar ID="TopBar" runat="server">
                        <Items>
                            <ext:ToolbarFill runat="server">
                            </ext:ToolbarFill>
                            <ext:Button ID="Button2" runat="server" Text="新增" Icon="Add">
                                <Listeners>
                                    <Click Handler="#{EditFormPanel}.form.reset();#{FIdH}.setValue(null);" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button1" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                     <Click Handler="#{EditFormPanel}.form.submit({waitMsg:'正在保存...', params:{fId:#{FIdH}.getValue(),fModelId:#{Select_ModelType}.getValue(),fUnitId:#{Select_Util}.getValue()},success:BD_Product.Mgr.successHandler , failure:BD_Product.Mgr.failureHandler});" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:Panel runat="server" Border="false" Header="false" Layout="FormLayout" LabelAlign="Left"
                        Padding="5">
                        <Items>
                            <ext:TextField ID="Input_ProductNumber" Name="fNumber" DataIndex="ProductNumber"
                                runat="server" FieldLabel="序号" AllowBlank="false" BlankText="序号不能为空" Width="150" />
                            <ext:TextField ID="Input_ProductName" Name="fName" DataIndex="ProductName" runat="server"
                                FieldLabel="品名" AllowBlank="false" BlankText="品名不能为空" Width="150" />
                         </Items>
                    </ext:Panel>
                    <ext:Panel ID="Panel1" runat="server" Border="false" Header="false" Layout="FormLayout" LabelAlign="Left"
                        Padding="5">
                        <Items>
                            <ext:ComboBox ID="Select_ModelType" DataIndex="ProductModelId" StoreID="ModelTypeStore"
                                runat="server" FieldLabel="规格" DisplayField="FName" ValueField="FId" AllowBlank="false"
                                EmptyText="请选择规格..." Width="150" Flex="2" Editable="false">
                                <Listeners>
                                    <BeforeRender Handler="this.onTriggerClick = this.onTriggerClick.createSequence(function () {
                                                               Ext.net.DirectMethods.OnTriggerClick();
                                                           });" />
                                </Listeners>
                            </ext:ComboBox>
                            <ext:ComboBox ID="Select_Util" DataIndex="ProductUnitId" StoreID="UnitStore"
                                runat="server" FieldLabel="单位" DisplayField="FName" ValueField="FId" AllowBlank="false"
                                EmptyText="请选择单位..." Width="150" Flex="2" Editable="false">
                                 <Listeners>
                                    <BeforeRender Handler="this.onTriggerClick = this.onTriggerClick.createSequence(function () {
                                                               Ext.net.DirectMethods.OnTriggerClick();
                                                           });" />
                                </Listeners>
                            </ext:ComboBox>
                         </Items>
                    </ext:Panel>
                   <%-- <ext:Panel ID="Panel2" runat="server" Border="false" Layout="FormLayout" LabelAlign="Left"
                        Padding="5">
                        <Items>
                            <ext:TextField ID="Input_ProductPrice1" Name="fPrice1" DataIndex="ProductPrice1"
                                runat="server" FieldLabel="单价1" AllowBlank="true" Width="150" />
                            <ext:TextField ID="Input_ProductPrice2" Name="fPrice2" DataIndex="ProductPrice2"
                                runat="server" FieldLabel="单价2" AllowBlank="true" Width="150" />
                            <ext:TextField ID="Input_ProductPrice3" Name="fPrice3" DataIndex="ProductPrice3"
                                runat="server" FieldLabel="单价3" AllowBlank="true" Width="150" />
                        </Items>
                    </ext:Panel>--%>
                    <ext:Panel ID="Panel3" runat="server" Border="false" Layout="FormLayout" LabelAlign="Left"
                        Padding="5">
                        <Items>
                            <ext:TextField ID="Input_ProductQty" Name="fQty" DataIndex="ProductQty" runat="server"
                                FieldLabel="库存量" AllowBlank="false" BlankText="库存量不能为空" Width="150" />
                            <ext:TextField ID="Input_ProductRemark" Name="fReMark" DataIndex="ProductRemark"
                                runat="server" FieldLabel="备注" AllowBlank="true" Width="150" />
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:FormPanel>
            <ext:FormPanel ID="SearchFormPanel" runat="server" Title="筛选条件" Region="West" Width="250"
                Split="true" Collapsible="true" Layout="FormLayout" Padding="5" LabelWidth="50">
                <Items>
                    <ext:TextField ID="InputQ_ProductNumber" runat="server" FieldLabel="序号" AnchorHorizontal="100%"
                        Width="180" />
                    <ext:TextField ID="InputQ_ProductName" runat="server" FieldLabel="品名" AnchorHorizontal="100%"
                        Width="180" />
                    <ext:ComboBox ID="InputQ_ModelTypeSelect" StoreID="ModelTypeStore" runat="server"
                        FieldLabel="规格" DisplayField="FName" ValueField="FId" AllowBlank="true" EmptyText="请选择规格..."
                        Width="180" Flex="2">
                        <Listeners>
                            <BeforeRender Handler="this.onTriggerClick = this.onTriggerClick.createSequence(function () {
                                                               Ext.net.DirectMethods.OnTriggerClick();
                                                           });" />
                        </Listeners>
                    </ext:ComboBox>
                    <ext:TextField ID="InputQ_ProductRemark" runat="server" FieldLabel="备注" AnchorHorizontal="100%"
                        Width="180" />
                    <ext:ComboBox ID="InputQ_ProductInvStatus" StoreID="productInvStore" runat="server"
                        FieldLabel="产品状态" DisplayField="FName" ValueField="FNumber" AllowBlank="true"
                        EmptyText="请选择产品状态..." Width="180" Flex="2">
                    </ext:ComboBox>
                </Items>
                <Buttons>
                    <ext:Button ID="Button5" runat="server" Text="搜索" Icon="Accept">
                        <Listeners>
                            <Click Fn="BD_Product.Mgr.searchList" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button6" runat="server" Text="清空" Icon="Cancel">
                        <Listeners>
                            <Click Fn="BD_Product.Mgr.resetSearchFrom" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
            <ext:Panel ID="Panel4" runat="server" Region="Center" Layout="AccordionLayout" Split="true"
                Header="false">
                <Items>
                    <ext:GridPanel ID="ProductGrid" runat="server" Border="false" StoreID="ProductListStore"
                        StripeRows="true" TrackMouseOver="true" ClicksToEdit="0" Region="Center">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server">
                                    </ext:ToolbarFill>
                                    <ext:Button ID="export" runat="server" Text="导出并打印" Icon="Printer">
                                        <Listeners>
                                            <Click Fn="BD_Product.Mgr.Print" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel ID="ColumnModel1" runat="server" DefaultSortable="false">
                            <Columns>
                                <ext:Column ColumnID="ProductId" DataIndex="ProductId" Header="ID" Hidden="true">
                                </ext:Column>
                                <ext:Column ColumnID="ProductNumber" DataIndex="ProductNumber" Header="序号" Sortable="true">
                                </ext:Column>
                                <ext:Column ColumnID="ProductName" DataIndex="ProductName" Header="品名">
                                </ext:Column>
                                <ext:Column ColumnID="ProductModelName" DataIndex="ProductModelName" Header="规格">
                                </ext:Column>
                                <ext:Column ColumnID="ProductUnitName" DataIndex="ProductUnitName" Header="单位">
                                </ext:Column>
                                <%--<ext:Column ColumnID="ProductPrice1" DataIndex="ProductPrice1" Header="单价1">
                                </ext:Column>
                                <ext:Column ColumnID="ProductPrice2" DataIndex="ProductPrice2" Header="单价2">
                                </ext:Column>
                                <ext:Column ColumnID="ProductPrice3" DataIndex="ProductPrice3" Header="单价3">
                                </ext:Column>--%>
                                <ext:Column ColumnID="ProductQty" DataIndex="ProductQty" Header="库存">
                                </ext:Column>
                                <ext:Column ColumnID="ProductRemark" DataIndex="ProductRemark" Header="备注">
                                </ext:Column>
                                <ext:CommandColumn Width="80" Hideable="false">
                                    <Commands>
                                        <ext:GridCommand CommandName="Edit" Icon="ApplicationFormEdit" Text="修改">
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                                <ext:CommandColumn Width="60" Hideable="false">
                                    <Commands>
                                        <ext:GridCommand CommandName="Delete" Icon="Cross" Text="删除">
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                            </Columns>
                        </ColumnModel>
                        <Listeners>
                            <HeaderClick Handler="if (columnIndex === 1) { changeProdNumSortDirect(); }" />
                        </Listeners>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server" StoreID="ProductListStore"
                                PageSize="15" />
                        </BottomBar>
                        <Listeners>
                            <Command Fn="BD_Product.Mgr.commandHandler" />
                        </Listeners>
                        <LoadMask ShowMask="true" />
                    </ext:GridPanel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
</body>
</html>
